package cn.topevery.garden.dal.logic;

import cn.topevery.garden.dal.dao.ScenicFileDao;
import cn.topevery.garden.entity.po.ScenicFile;
import cn.topevery.garden.entity.query.ScenicFileQuery;
import cn.topevery.garden.framework.base.BaseLogic;
import hw.topevery.framework.db.base.BaseEntityDao;
import hw.topevery.framework.db.entity.DataPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 
 *
 * @author code-generate
 * @date 2021-08-31
 */
@Service
public class ScenicFileLogic extends BaseLogic<ScenicFile> {
    @Autowired
    ScenicFileDao scenicFileDao;

    @Override
    public BaseEntityDao<ScenicFile, Integer> getDao() {
        return scenicFileDao;
    }

    

    /**
     * 获取列表
     *
     * @param query
     */
    public DataPager<ScenicFile> listPage(ScenicFileQuery query) {
        return scenicFileDao.listPage(query);
    }

    public List<ScenicFile> getListByPid(Integer pid){
        return scenicFileDao.getListByPid(pid);
    }

    /**
     * 根据自增id批量删除
     *
     * @param ids
     */
    public void deleteBatchById(String userId,Integer[] ids) {
        scenicFileDao.delete(userId, ids);
    }

    /**
     * 根据自增id保存或者更新
     *
     * @param scenicFileList 实体
     */
    public void saveOrUpdate(String userId, Integer pid, List<ScenicFile> scenicFileList){
        scenicFileDao.deleteById(pid);
        for(ScenicFile scenicFile : scenicFileList){
            scenicFile.setMainId(pid);
            scenicFileDao.saveOrUpdate(userId,scenicFile);
        }
    }
}
